package top.asteam.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import top.asteam.entity.CommonResult;
import top.asteam.entity.Payment;

/**
 * @Author Rock Wang
 * @Time 2021/4/11
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
//    public static final String PAYMENT_URL="http://localhost:8001/data";
    public static final String PAYMENT_URL="http://cloud-payment-service/data";

    @Autowired
    private RestTemplate restTemplate;

    @PostMapping("/payment/create")
    public CommonResult<Payment> create(@RequestBody Payment payment){
        return restTemplate.postForObject(PAYMENT_URL+"/payment/save",payment,CommonResult.class);
    }

    @GetMapping("/payment/get")
    public CommonResult<Payment> getPaymentById(@RequestParam Long id){
        return restTemplate.getForObject(PAYMENT_URL+"/payment/getById?id="+id,CommonResult.class);
    }

    @GetMapping("/payment/zk")
    public CommonResult<Payment> getZK(){
        return restTemplate.getForObject(PAYMENT_URL+"/payment/zk",CommonResult.class);
    }

}
